home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: GoTo equivalent in C ??
- Date: Sat, 13 Jan 96 14:31:07 GMT
- Organization: none
- Message-ID: <821543467snz@genesis.demon.co.uk>
- References: <4d67vm$e5h@masala.cc.uh.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4d67vm$e5h@masala.cc.uh.edu> sukku@menudo.uh.edu "sukumar" writes:
-
- >Hi,
- > I have always thought about this. How do you get the effect of goto
- >in C without using "goto"?? For ex, if I have to check for an error in my
- >function for every computation I do, and then do some cleaning up, how do
- >I do it. Here is an example:
-
- Error handling is an area in C where using goto can be the best approach.
- Early languages such as FORTRAN 66 gave you little choice but to use goto
- for many constructs. Then structured programming ideas became established
- and there were lots of compelling arguments (Dijkstra is a notable name here)
- as to why this is a much better approach than spaghetti code. However even
- Dijkstra accepted that goto still had its uses and, indeed, with discipline
- you can program in a structured way using goto.
-
- >I don't want to use goto. what alternatievs do I have.
- >Any ideas are greatly appreciated.
-
- Don't look for alternatives that make your code more complex and difficult
- to follow. To be sure you very rarely need to use goto but there are
- a few cases where the normal structured if/for/while/do constructs just can't
- model the problem sensibly.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-